package com.djakapm.swing.component.table;

import com.djakapm.swing.common.ContainerFactory;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Vector;

public class SpecForTableView {
	static void can_create_table_view_with_rows_and_columns() {
		Vector<String> columns = new Vector<String>();
		columns.addElement("Name");
		columns.addElement("Address");
		columns.addElement("Title");
		Vector<Vector<Object>> rows = new Vector<Vector<Object>>();
		Vector<Object> row;
		
		row = new Vector<Object>();
		row.addElement("Fucker");
		row.addElement("St. Hell");
		row.addElement("Hell Consultant");
		rows.addElement(row);
		
		row = new Vector<Object>();
		row.addElement("Djaka PM");
		row.addElement("Jl. Sri Putri 4 1735B");
		row.addElement("Software Consultant");
		rows.addElement(row);
		
		JFrame frame = ContainerFactory.newFrame("Rows and Columns to Table View");
		frame.getContentPane().add(new TableView(rows,columns));
		frame.setVisible(true);
	}
	
	static void can_create_table_view_with_column_only() {
		Vector<String> columns = new Vector<String>();
		columns.addElement("Name");
		columns.addElement("Address");
		columns.addElement("Title");
		JFrame frame = ContainerFactory.newFrame("Columns only to Table View");
		frame.getContentPane().add(new TableView(columns));
		frame.setVisible(true);
	}
	
	static void can_add_row_to_table_view() {
		Vector<String> columns = new Vector<String>();
		columns.addElement("Post Name");
		columns.addElement("Post Address");
		columns.addElement("Post Title");
		Table table = new Table(columns);
		JFrame frame = ContainerFactory.newFrame("Add Rows after initialize to Table View");
		frame.getContentPane().add(new TableView(table));
		frame.setVisible(true);
		Vector<Object> row = new Vector<Object>();
		row.addElement("XXXXXX");
		row.addElement("YYYYYY");
		row.addElement("ZZZZZZ");
		table.addRow(row);
	}
	
	static void can_add_row_using_fluent_method_to_table_view() {
		Vector<String> columns = new Vector<String>();
		columns.addElement("Name");
		columns.addElement("Address");
		columns.addElement("Title");
		Table table = new Table(columns);
		JFrame frame = ContainerFactory.newFrame("Add Rows using fluent method to Table View");
		frame.getContentPane().add(new TableView(table));
		frame.setVisible(true);
		table
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun");
	}
	
	static void can_add_row_using_fluent_method_partial_column_to_table_view() {
		Vector<String> columns = new Vector<String>();
		columns.addElement("Name");
		columns.addElement("Address");
		columns.addElement("Title");
		Table table = new Table(columns);
		JFrame frame = ContainerFactory.newFrame("Add Rows using fluent method partial columns to Table View");
		frame.getContentPane().add(new TableView(table));
		frame.setVisible(true);
		table
		.addRow("Dadang","Jl. Wakuncar")
		.addRow("Suparman")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun");
	}
	
	static void can_add_show_selected_cell_value() {
		Vector<String> columns = new Vector<String>();
		columns.addElement("Name");
		columns.addElement("Address");
		columns.addElement("Title");
		Table table = new Table(columns);
		table.addMouseListener(new MouseAdapter() {
			@Override
			 public void mouseClicked(MouseEvent e) {
				 Table table = (Table)e.getSource();
				 System.out.println(table.getValue());
				 System.out.println(table.getRow());
			 }
			 @Override
			 public void mouseReleased(MouseEvent e) {
				 Table table = (Table)e.getSource();
				 System.out.println(table.getRows());
			 }
		});
		JFrame frame = ContainerFactory.newFrame("Add Rows using fluent method partial columns to Table View");
		frame.getContentPane().add(new TableView(table));
		frame.setVisible(true);
		table
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun");
	}
	static void can_clear_content() {
		Vector<String> columns = new Vector<String>();
		columns.addElement("Name");
		columns.addElement("Address");
		columns.addElement("Title");
		Table table = new Table(columns);
		table.addMouseListener(new MouseAdapter() {
			@Override
			 public void mouseClicked(MouseEvent e) {
				 Table table = (Table)e.getSource();
				 System.out.println(table.getValue());
				 System.out.println(table.getRow());
			 }
			 @Override
			 public void mouseReleased(MouseEvent e) {
				 Table table = (Table)e.getSource();
				 System.out.println(table.getRows());
			 }
		});
		JFrame frame = ContainerFactory.newFrame("Clear content");
		frame.getContentPane().add(new TableView(table));
		frame.setVisible(true);
		table
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun")
		.addRow("Dadang","Jl. Wakuncar","Doc.")
		.addRow("Suparman","Jl.Kuburan","Guru")
		.addRow("Budiman Sutarjo","Jl.Sakar","Dukun");
		table.clear();
	}
	
	
	public static void main(String[] args) {
		SpecForTableView.can_create_table_view_with_rows_and_columns();
		SpecForTableView.can_create_table_view_with_column_only();
		SpecForTableView.can_add_row_to_table_view();
		SpecForTableView.can_add_row_using_fluent_method_to_table_view();
		SpecForTableView.can_add_row_using_fluent_method_partial_column_to_table_view();
		SpecForTableView.can_add_show_selected_cell_value();
		SpecForTableView.can_clear_content();
	}

}
